﻿// See https://aka.ms/new-console-template for more information
//Console.WriteLine("Hello, World!");



//Console.WriteLine(typeof(Task));

//Console.WriteLine(nameof(Task.FromResult));



using Apps.Excel;
using Newtonsoft.Json;
using NPOI.SS.UserModel;

string value = "123";

//var a=typeof(Task).GetMethod(nameof(Task.FromResult)).MakeGenericMethod(typeof(string)).Invoke(null,new[] { value });

//var returnValue = typeof(Task<>).MakeGenericType(typeof(string)).GetProperty(nameof(Task<object>.Result)).GetValue(value);


//Type t = typeof(string);

//var a=typeof(Task<>).GetMethod(nameof(Task.FromResult));

Console.WriteLine(JsonConvert.SerializeObject(value));



//ttt s= await bbb();


//Console.WriteLine();






//try
//{
//创建Excel
//IWorkbook workbook=ExcelOperationHelper.CreateExcelWorkbook();
//using FileStream file = new FileStream(@"F:\Desktop\ConsoleApp3\ConsoleApp3\student.xls", FileMode.Create);
//workbook.Write(file);

//导出到文件
List<ExcelDataResource> dataResources = GetExcelDataList();
IWorkbook workbook = ExcelOperationHelper.DataToHSSFWorkbook(dataResources);
////using FileStream fs = new FileStream(@"F:\Desktop\ConsoleApp3\ConsoleApp3\aaa.xls", FileMode.Create);
using FileStream fs = new FileStream(@"F:\Desktop\ConsoleApp3\ConsoleApp3\aaa.xlsx", FileMode.Create);
workbook.Write(fs);


//转换成字节数组和内存流
//List<ExcelDataResource> excelDataList = GetExcelDataList();
//IWorkbook workbook1 = ExcelOperationHelper.DataToHSSFWorkbook(excelDataList);
//byte[] btarray = ExcelOperationHelper.ToExcelByteArray(excelDataList);
//MemoryStream memoryStream=ExcelOperationHelper.ToExcelMemoryStream(excelDataList);

List<ExcelDataResource> excelDataList=GetExcelDataList();
//IWorkbook workbook2=ExcelOperationHelper.DataToHSSFWorkbook(excelDataList);
byte[] btarray=ExcelOperationHelper.ToExcelByteArray(excelDataList);
MemoryStream memoryStram = ExcelOperationHelper.ToExcelMemoryStream(excelDataList);



Console.ReadKey();

//}
//catch (Exception)
//{

//    throw;
//}


static List<ExcelDataResource> GetExcelDataList()
{
    List<object> objlist = new List<object>();
    for (int i = 0; i < 100; i++)
    {
        objlist.Add(new UserInfo()
        {
            UserId = i + 1,
            UserName = $"名称-{i}",
            Age = i + i + 1,
            UserType = i + 1,
            Description = $"描述——描述{i}"
        });

    }

    List<object> classobjlist = new List<object>();
    for (int i = 0; i < 280; i++)
    {
        classobjlist.Add(new ClassInfo()
        {
            ClassId = i + 1,
            ClassName = $"班级-{i}",
        });
    }


    return new List<ExcelDataResource>()
    {
        new ExcelDataResource()
        {
            SheetName="页签1",
            TitleIndex=5,
            SheetDataResource=objlist
        },
         new ExcelDataResource()
        {
            SheetName="页签2",
            TitleIndex=3,
            SheetDataResource=classobjlist
        }
    };
}



//await foreach (var item in ddd())
//{
//    Console.WriteLine(item);
//}

//Console.ReadKey();



//Task<ttt> bbb()
//{
//    return Task.FromResult<ttt>(new ttt() { id = 1, name = "哈哈" });
//}


//Task ccc()
//{
//    return Task.CompletedTask;
//}

//async IAsyncEnumerable<string> ddd()
//{
//    yield return "111";
//    yield return "222";
//    yield return "333";
//}


//async Task<string> aaa()
//{
//    await Task.Run(() =>
//    {
//        return "123";
//    });

//    return "666";
//}

//public class ttt
//{
//    public int id { get; set; }
//    public string name { get; set; }
//}